package aom.ju.ss.view.user.shop.management.order

import android.os.Bundle
import androidx.core.content.ContextCompat
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import aom.ju.ss.R
import aom.ju.ss.databinding.OrderListFragmentBinding
import aom.ju.ss.databinding.OrderManageBinding
import aom.ju.ss.view.base.BaseActivity
import aom.ju.ss.view.base.BaseFragment
import aom.ju.ss.view.base.BaseListFragment
import aom.ju.ss.view.base.TopBar
import aom.ju.ss.view.main.LpViewModel

class OrderListFragment : BaseFragment() {
    private lateinit var binding: OrderListFragmentBinding

    companion object {
        fun getMy(type: String, data: String = ""): OrderListFragment {
            val f = OrderListFragment()
            val b = Bundle()
            b.putString("type", type)
            b.putString("data", data)
            f.arguments = b
            return f
        }
    }

    var type = ""// 0 订单 1 售后
    var data = ""
    var fs = arrayListOf<Fragment>()
    var ts = arrayListOf<String>()
    override fun init() {
        binding = viewBinding as OrderListFragmentBinding
        type = requireArguments().getString("type", "")
        data = requireArguments().getString("data", "")
        if (type == "0") {
            fs.add(OrderListItemFragment.getMy("0"))
            fs.add(OrderListItemFragment.getMy("1"))
            fs.add(OrderListItemFragment.getMy("2"))
            fs.add(OrderListItemFragment.getMy("3"))

            ts.add("全部")
            ts.add("待付款")
            ts.add("待发货")
            ts.add("已发货")
        } else {
            fs.add(OrderListItemSHFragment.getMy("1"))
            fs.add(OrderListItemSHFragment.getMy("2"))
            fs.add(OrderListItemSHFragment.getMy("3"))

            ts.add("平台处理中")
            ts.add("平台处理中")
            ts.add("待买家处理")
        }

        binding.vp.adapter = object : FragmentPagerAdapter(childFragmentManager, 1) {
            override fun getCount(): Int {
                return fs.size
            }

            override fun getItem(position: Int): Fragment {
                return fs[position]
            }

            override fun getPageTitle(position: Int): CharSequence? {
                return ts[position]
            }
        }
        binding.tab.setupWithViewPager(binding.vp)
        binding.vp.offscreenPageLimit = 5
        if (data == "3") {
            binding.vp.currentItem = 2
        }

    }

    override fun getLay(): Int {
        return R.layout.order_list_fragment
    }


}